﻿using D3StatsClient.ViewModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

namespace D3StatsClient.Model
{
    public static class ViewModelManager<T> where T : ViewModelBase
    {
        private static ObservableCollection<T> ViewModels = new ObservableCollection<T>();

        public static T ViewModel  
        {
            get
            {
                return (from l in ViewModels where l.GetType() == typeof(T) select l).FirstOrDefault();
            }
            set
            {
                var model = (from l in ViewModels where l.GetType() == typeof(T) select l).FirstOrDefault();

                if (model == null)
                {
                    ViewModels.Add(value);

                }
                else
                {
                    var index = ViewModels.IndexOf((from l in ViewModels where l.GetType() == typeof(T) select l).FirstOrDefault());

                    ViewModels[index] = value;
                }
            }
        }
    }
}
